package com.spzx.product.service.impl;



import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spzx.product.domain.Brand;
import com.spzx.product.domain.CategoryBrand;
import com.spzx.product.mapper.CategoryBrandMapper;
import com.spzx.product.service.CategoryBrandService;
import com.spzx.product.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryBrandServiceImpl extends ServiceImpl<CategoryBrandMapper, CategoryBrand>
        implements CategoryBrandService {


    @Autowired
    private CategoryService categoryService;
//查询分类品牌列表
    @Override
    public List<CategoryBrand> selectCategoryBrandList(CategoryBrand categoryBrand) {
        List<CategoryBrand> list = baseMapper.selectCategoryBrandList(categoryBrand);
        return list;
    }

    @Override
    public CategoryBrand selectCategoryBrandById(Long id) {
        //根据id查询
        //CategoryBrand categoryBrand = this.getById(id);
        CategoryBrand categoryBrand = baseMapper.selectById(id);
        //根据当前第三层分类id，获取第二层和第一层分类id
        Long categoryId = categoryBrand.getCategoryId();
        List<Long> categoryIdList = categoryService.getAllCategoryById(categoryId);
        categoryBrand.setCategoryIdList(categoryIdList);

        return categoryBrand;
    }


    //根据分类ID获取对应品牌数据
    @Override
    public List<Brand> selectBrandListByCategoryId(Long categoryId) {
        return baseMapper.selectBrandListByCategoryId(categoryId);

    }

}

